body{
    margin: 4px;
    height: 100%;
}
.masonry{
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    height: 1000px;
}

.item{
    position: relative;
    width: 25%;
    padding: 2px;
    box-sizing: border-box;
}
.item:nth-child(4n+1){
    order: 1;
}
.item:nth-child(4n+2){
    order: 2;
}
.item:nth-child(4n+3){
    order: 3;
}
.item:nth-child(4n){
    order: 3;
}